<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}
else
    
include 'maintenance.html';
                
    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());
    
    switch($_GET['action']) {
        case 'edit':
    
            switch ($_GET['type']) {
            case 'mait':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Function to make a valid date input if it has a space colon or period as a seperator
            $date = $year."-".$month."-".$day;

            //SQL Query
            $qry = "update maintenance set type='".$_POST['category']."', notes='".$_POST['notes']."' where m_date = '".$_GET['m_date']."' and user_id='".$_SESSION['uid'] ."'";

            break;
           
            case 'water':                

            //Date variables
            $day = $_POST['day'];
            $month = $_POST['month'];
            $year = $_POST['year'];

            //Date variables
            $day2 = $_POST['day2'];
            $month2 = $_POST['month2'];
            $year2 = $_POST['year2'];

            //Function to make a valid date input
            $changedate = $year."-".$month."-".$day;
            $nextchangedate = $year2."-".$month2."-".$day2;

            //SQL Query to add tank info
            $qry = "update waterchange set next_change='$nextchangedate',quantity='".$_POST['qty']."',tank='".$_POST['tanktype']."',salt_used='".$_POST['salt']."' where change_date = '".$_GET['change_date']."' and user_id='".$_SESSION['uid'] ."'";

            break;
           }
           
        break;
      }
        
        //Execute Insert command
        if (!mysql_query($qry,$con))
            {
              die('Error: ' . mysql_error());
            }
            echo "Activity updated!"; 
            //echo $qry;
               
    //Close SQL input
    mysql_close($con);

?>
